package framework;

import plugins.ConwayCell;
import plugins.DeadState;
import interfaces.Board;
import interfaces.Cell;

public class BoardImpl implements Board {
	protected int width;
	protected int height;
	protected Cell[][] cells;

	/**
	 * Creates a new board filled with Dead ConwayCells
	 * @param width width of board
	 * @param height height of board
	 */
	public BoardImpl(int width, int height) {
		this.width = width;
		this.height = height;

		cells = new Cell[width][height];
		// fill board with cells.
		for (int x = 0; x < width; x++)
			for (int y = 0; y < height; y++)
			{
				cells[x][y] = new ConwayCell(); // how will we know what to load with?
				cells[x][y].setBoard(this); //this needed?
				//cells[x][y].setAlgorithm(a);
				cells[x][y].setState(new DeadState()); //make all cells dead
			}
	}

//	// make sure cells 2d Array is right dimmension (loop thru)
//	public BoardImpl(Cell[][] cells, int x, int y) {
//		this.width = cells.length;
//		this.height = cells[0].length;
//		cells = new Cell[width][height];
//		// fill board with cells.
//		for (int x = 0; x < width; x++)
//			for (int y = 0; y < height; y++)
//			{
//				cells[x][y] = new ConwayCell(); // how will we know what to load with?
//				cells[x][y].setBoard(this); //this needed?
//				//cells[x][y].setAlgorithm(a);
//				cells[x][y].setState(new DeadState()); //make all cells dead
//			}
//	}
@Override
	public Cell[][] getCells() {
		return cells;
	}

	@Override
	public Cell getCell(int x, int y) {
		if ( (x < 0 || x >= width) || (y < 0 || y >= height) )
			return null;
		return cells[x][y];
	}
	
//	//TODO fix this (make location class+direction constant clas w satic vars
//	public Location getCellLocation(Cell c)
//	{
//		
//	}

	@Override
	/**
	 * Is this needed?  If so, testing needed.
	 */
	public void setCell(Cell c, int x, int y) {
		if ( (x < 0 || x >= width) || (y < 0 || y >= height) )
			return;
		cells[x][y] = c;
	}

	@Override
	public void setWidth(int w) {
		width = w;
		
	}

	@Override
	public void setHeight(int h) {
		height = h;
	}

	@Override
	public int getWidth() {
		return width;
	}

	@Override
	public int getHeight() {
		return height;
	}

}
